﻿Option Explicit On ' Make sure all items are explicitly declared
Option Strict On ' Be Very Strict about things here!
Imports System.IO
Imports System.Media
''' <summary>Social</summary>
''' <author>Comentsys</author>
''' <version>3.0.0</version>
''' <created>10th February 2009</created>
''' <modified>23rd February 2009</modified>
''' <remarks>ZuneCardr Main Interface</remarks>
Class Main

    ' Private Constants

    Private ReadOnly APP_NAME As String = My.Application.Info.ProductName ' Application Name
    Private ReadOnly APP_VERSION As String = My.Application.Info.Version.ToString ' Application Version
    Private ReadOnly SUCCESS_COLOUR As Brush = Brushes.Goldenrod
    Private ReadOnly FAILED_COLOUR As Brush = Brushes.Maroon
    Private ReadOnly PENDING_COLOUR As Brush = Brushes.Black
    Private Const APP_WEBLINK As String = "http://www.zunecardr.com"
    Private Const APP_WEBLINK_PARTIAL As String = "zunecardr.com"
    Private Const APP_WEBLINK_TEXT As String = "ZuneCardr.com"
    Private Const STATUS_TODO As String = "To Do"
    Private Const STATUS_SUCCESS As String = "Success"
    Private Const STATUS_FAILED As String = "Failed"
    Private Const STATUS_PENDING As String = "Pending"
    Private Const EVENT_DOWNLOAD As String = "Download"
    Private Const EVENT_PROCESS As String = "Process"
    Private Const LABEL_NEXT As String = "_Next"
    Private Const LABEL_FINISH As String = "_Finish"
    Private Const LABEL_FAVS As String = "Favourites"
    Private Const LABEL_RECENT As String = "Recent"
    Private Const LABEL_ARTISTS As String = "Artists"
    Private Const LABEL_BADGES As String = "Badges"
    Private Const LABEL_SEND As String = "Send"
    Private Const LABEL_PAGE As String = "Page"
    Private Const LABEL_DETAILS As String = "Details"
    Private Const LABEL_ABOUT As String = "About"
    Private Const LABEL_WEBLINK As String = "Weblink HTML"
    Private Const MESSAGE_TAG As String = "Please enter a Zune Tag"
    Private Const MESSAGE_FINISH As String = "If you have Saved or Copied your Zune Card Image then do you want to Exit?"
    Private Const MESSAGE_CUSTOM As String = "There was a problem with opening the file for that Custom Style"
    Private Const MESSAGE_BADGES As String = " does not have any Badges"
    Private Const MESSAGE_SETTINGS_SAVE As String = "There was a problem with Saving the Settings"
    Private Const MESSAGE_SETTINGS_OPEN As String = "The Settings file could not be Opened"
    Private Const MESSAGE_SAVE As String = "There was a problem Saving the Card Image"
    Private Const FILTER_CUSTOM As String = "XAML (*.xaml)|*.xaml"
    Private Const FILTER_SAVE As String = "JPEG - Zune Compatible (*.jpg)|*.jpg|Bitmap (*.bmp)|*.bmp|GIF (*.gif)|*.gif|Tagged Image File Format (*.tif)|*.tif|Portable Network Graphics (*.png)|*.png"
    Private Const FILTER_ZUNECARDR As String = "ZuneCardr Settings (*.zcr)|*.zcr"
    Private Const ZUNE_COLOUR As String = "Zune Colour"
    Private Const ITEM_COLOUR As String = "Select Colour"
    Private Const NAME_PREFIX As String = "Z"
    Private Const THEME_PREFIX As String = "T"
    Private Const SIZE_PREFIX As String = "S"
    Private Const CUSTOM_PREFIX As String = "C"
    Private Const CARD_CUSTOM As String = "(Custom)"
    ' Zune Devices
    Private Const RES_DEVICE As String = "Device"
    Private Const RES_DEVICE_KEEL As String = "Keel"
    Private Const RES_DEVICE_SCORPIUS As String = "Scorpius"
    Private Const RES_DEVICE_DRACO As String = "Draco"
    ' Zune Types
    Public Const ZUNE_4 As String = "4GB"
    Public Const ZUNE_8 As String = "8GB"
    Public Const ZUNE_16 As String = "16GB"
    Public Const ZUNE_30 As String = "30GB"
    Public Const ZUNE_80 As String = "80GB"
    Public Const ZUNE_120 As String = "120GB"

    ' Private Members

    Private ErrorLog As String = "" ' Error Log
    Private CurrentStep As Integer = 1
    Private MessageDialog As New Dialog ' Message Dialog
    Private ColorDialog As New ColorDialog ' Color Dialog
    Private Settings As New ZuneCardr.Settings ' Settings Data
    Private WithEvents Social As New ZuneCardr.Social ' Zune Social Data
    Private Card As New ZuneCardr.Card ' Zune Card Output
    Private _Items As New List(Of ZuneCardr.Item) ' All Playlist

    ' Event Handlers

    ''' <summary>HandleRequestNavigate</summary>
    ''' <param name="sender">Hyperlink</param>
    ''' <param name="e">Event Arguments</param>
    ''' <remarks>Handles Hyperlink Click to Launch Browser</remarks>
    Private Sub HandleRequestNavigate(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Process.Start(CType(sender, Hyperlink).NavigateUri.ToString()) ' Go to Uri
        e.Handled = True ' Event Handled
    End Sub

    ''' <summary>HandleRequestTag</summary>
    ''' <param name="sender">Hyperlink</param>
    ''' <param name="e">Event Arguments</param>
    ''' <remarks>Handles Hyperlink Click to fill Zune Tag TextBox</remarks>
    Private Sub HandleRequestTag(ByVal sender As Object, ByVal e As RoutedEventArgs)
        ZuneTag.Text = (CType(sender, Hyperlink).NavigateUri.ToString()) ' Load URL Tag
        e.Handled = True ' Event Handled
    End Sub

    ''' <summary>Downloaded</summary>
    ''' <param name="Success">Download Success</param>
    ''' <remarks>Handles the Downloaded Event</remarks>
    Private Sub Downloaded(ByVal Success As Boolean) Handles Social.Downloaded
        If Success Then
            GetStatus(STATUS_SUCCESS, EVENT_DOWNLOAD, Downloading.Content, _
                      Downloading.Foreground) ' Download Succeeded
        Else
            Me.Cursor = Cursors.Arrow ' Reset Cursor
            GetStatus(STATUS_FAILED, EVENT_DOWNLOAD, Downloading.Content, _
                      Downloading.Foreground) ' Download Failed
        End If
    End Sub

    ''' <summary>Processed</summary>
    ''' <param name="Success">Process Success</param>
    ''' <remarks>Handles the Processed Event</remarks>
    Private Sub Processed(ByVal Success As Boolean) Handles Social.Processed
        If Success Then
            If Social.Message <> "" Then ' Check for Error Message
                Err.Raise(514, Social.Message, Social.Message) ' Invalid Zune Tag
            End If
            GetStatus(STATUS_SUCCESS, EVENT_PROCESS, Processing.Content, _
                      Processing.Foreground) ' Download Succeeded
            ProfileAvatar.Source = Social.Avatar(ZuneCardr.Social.ImageVersion.Large) ' Avatar Image
            ProfileAvatar.Visibility = Windows.Visibility.Visible ' Show Avatar
            ProfileTag.Visibility = Windows.Visibility.Visible ' Show Tag
            SetCard() ' Set Card Data
            Items.Clear() ' Clear All Playlist
            GetPlaylists(lstFavourites, lstRecent, lstArtists) ' Get Playlists
            GetBadges(lstBadges) ' Get Badges
            GetItems(lstAll) ' Get All (Playlists and Badges)
            GetLinks() ' Get Profile Links
            cboSource.SelectedIndex = 0 ' Set Source DropDown
            cboStyle.SelectedIndex = 0 ' Set Style Drop Down
            Me.Cursor = Cursors.Arrow ' Reset Cursor
            StepTwo(cvsStepOne) ' Go to Step Two
        Else
            Me.Cursor = Cursors.Arrow ' Reset Cursor
            GetStatus(STATUS_FAILED, EVENT_PROCESS, Processing.Content, _
                      Processing.Foreground) ' Download Failed
        End If
    End Sub

    ' Private Methods

    ''' <summary>ShowColorDialog</summary>
    ''' <param name="Color">Default / Original Colour</param>
    ''' <param name="Title">Dialog Title</param>
    ''' <param name="Presets">Preset List Class</param>
    ''' <returns>Color</returns>
    ''' <remarks>Helper Method</remarks>
    Private Function ShowColorDialog(ByVal Color As Color, _
                                     ByVal Title As String, _
                                     ByVal Presets As Dictionary(Of String, Color)) As Color
        ColorDialog.Color = Color
        ColorDialog.Presets = Presets
        ColorDialog.ShowDialog(Title)
        If ColorDialog.Selected Then
            Return ColorDialog.Color
        Else
            Return Color
        End If
    End Function

    ''' <summary>ColourSquare</summary>
    ''' <param name="Color">Square Colour</param>
    ''' <returns>Rectangle</returns>
    ''' <remarks>Helper Method</remarks>
    Private Function ColourSquare(ByVal Color As Color) As Rectangle
        Dim Square As New Rectangle
        Square.Fill = New SolidColorBrush(Color)
        Square.Height = 16
        Square.Width = 16
        Square.Stroke = Brushes.Black
        Return Square
    End Function

    ''' <summary>ResetIndicators</summary>
    ''' <remarks>Reset Progress Indicators</remarks>
    Private Sub ResetIndicators()
        Downloading.Foreground = Brushes.Black
        Downloading.Content = STATUS_TODO
        Processing.Foreground = Brushes.Black
        Processing.Content = STATUS_TODO
    End Sub

    ''' <summary>GetStatus</summary>
    ''' <param name="Status">Status as String</param>
    ''' <param name="Name">Event Name</param>
    ''' <param name="Text">Label Text</param>
    ''' <param name="Colour">Label Colour</param>
    ''' <remarks>Set LabelText to Status Value and LabelColour to Status Colour</remarks>
    Private Sub GetStatus(ByRef Status As String, ByRef Name As String, ByRef Text As Object, ByRef Colour As Brush)
        Select Case Status ' Which Status
            Case STATUS_SUCCESS ' No Problems
                Text = STATUS_SUCCESS ' Set Text
                Colour = SUCCESS_COLOUR ' Set Colour
                ErrorLog = ErrorLog & Name & " : " & STATUS_SUCCESS & vbCrLf & vbCrLf ' Add Successfull items to Error Log
            Case STATUS_FAILED ' Error Condition
                Text = STATUS_FAILED & " : " & Social.ErrorText ' Set Error Text
                Colour = FAILED_COLOUR ' Set Colour
                ErrorLog = ErrorLog & Name & " " & STATUS_FAILED & ":" & vbCrLf & Social.ExceptionText & vbCrLf & vbCrLf ' Add to Error Log
            Case Else ' Other / Pending Status
                Text = STATUS_PENDING ' Set Text
                Colour = PENDING_COLOUR ' Set Colour
        End Select
    End Sub

    ''' <summary>SetCard</summary>
    ''' <remarks>Sets the Card Data</remarks>
    Private Sub SetCard()
        Card.Tag = Social.Tag
        Card.Plays(True) = Social.Plays(True) ' Numeric
        Card.Plays(False) = Social.Plays(False) ' Full
        Card.Badges = CStr(Social.Badges.Count)
        Card.Status = Social.Status
        Card.LastPlayed = Social.LastPlayed
        Card.Weblink = Social.Weblink
        Card.Location = Social.Location
        Card.Biography = Social.Biography
        ' Links
        ProfileHome.NavigateUri = New Uri(Social.Weblink)
        ProfileMessage.NavigateUri = New Uri(Social.MessageURL)
        ProfileSend.NavigateUri = New Uri(Social.SendURL)
        ' Zune
        Card.ZuneColour = Color.FromRgb(28, 28, 28) ' Black
        Card.Zune = ZuneCardr.Card.ZUNE_80 ' 80GB
        ' Images
        Card.AvatarImage = Social.Avatar(ZuneCardr.Social.ImageVersion.Large)
        Card.BackgroundImage = Social.Background(ZuneCardr.Social.ImageVersion.Large)
    End Sub

    ''' <summary>GetMessage</summary>
    ''' <param name="Message">Message Text</param>
    ''' <param name="TextBlock">TextBlock</param>
    ''' <remarks>Gets Message from Playlist</remarks>
    Private Sub GetMessage(ByRef Message As String, ByRef TextBlock As TextBlock)
        If Message <> "" Then
            TextBlock.Text = Message
            TextBlock.Visibility = Windows.Visibility.Visible
        Else
            TextBlock.Text = ""
            TextBlock.Visibility = Windows.Visibility.Hidden
        End If
    End Sub

    ''' <summary>GetPlaylists</summary>
    ''' <param name="Favourites">Favourites List</param>
    ''' <param name="Recent">Recently Played</param>
    ''' <param name="Played">Artists List</param>
    ''' <remarks>Gets ListBox Data for Playlists</remarks>
    Private Sub GetPlaylists(ByRef Favourites As ListBox, ByRef Recent As ListBox, ByRef Played As ListBox)
        Dim Duplicates As New List(Of String)
        Favourites.Items.Clear() ' Clear Favourites
        Recent.Items.Clear() ' Clear Recent Plays
        Played.Items.Clear() ' Clear Played Artists
        For Each Playlist As ZuneCardr.Playlist In Social.Playlists
            Select Case Playlist.Type
                Case ZuneCardr.Playlist.FAVS ' Favourites
                    GetMessage(Playlist.Message, txtFavourites) ' Message
                    For Each Track As ZuneCardr.Track In Playlist.Tracks
                        If Duplicates.Contains(Track.ID) Then
                            Track.Selected = False
                        Else
                            Duplicates.Add(Track.ID)
                        End If
                        Favourites.Items.Add(Track) ' Add Track and Album Data
                        AddItem(Track.ID, Track.Album.ImageLarge, Track.Name, Track.Selected) ' Add to All
                    Next
                Case ZuneCardr.Playlist.RECENT ' Recent Plays
                    GetMessage(Playlist.Message, txtRecent) ' Message
                    For Each Track As ZuneCardr.Track In Playlist.Tracks
                        If Duplicates.Contains(Track.ID) Then
                            Track.Selected = False
                        Else
                            Duplicates.Add(Track.ID)
                        End If
                        Recent.Items.Add(Track) ' Add Track and Album Data
                        AddItem(Track.ID, Track.Album.ImageLarge, Track.Name, Track.Selected) ' Add to All
                    Next
                Case ZuneCardr.Playlist.PLAYED ' Played Artists
                    GetMessage(Playlist.Message, txtArtists) ' Message
                    For Each Artist As ZuneCardr.Artist In Playlist.Artists
                        Played.Items.Add(Artist) ' Add Artist
                        AddItem(Artist.ID, Artist.ImageLarge, Artist.Name, Artist.Selected) ' Add to All
                    Next
            End Select
            Duplicates.Clear()
        Next
    End Sub

    ''' <summary>GetBadges</summary>
    ''' <param name="ListBox">ListBox</param>
    Private Sub GetBadges(ByRef ListBox As ListBox)
        ListBox.Items.Clear() ' Reset ListBox
        If Social.Badges.Count < 1 Then
            GetMessage(Social.Tag & MESSAGE_BADGES, txtBadges)
        Else
            GetMessage("", txtBadges)
        End If
        For Each Badge As ZuneCardr.Badge In Social.Badges
            ListBox.Items.Add(Badge) ' Add Badge
            AddItem(Badge.ID, Badge.ImageLarge, Badge.Name, Badge.Selected) ' Add to All
        Next
    End Sub

    ''' <summary>AddItem</summary>
    ''' <param name="ID">ID</param>
    ''' <param name="Image">Image</param>
    ''' <param name="Text">Text</param>
    ''' <param name="Selected">Selected</param>
    ''' <remarks>Add to AllItems List</remarks>
    Private Sub AddItem(ByVal ID As String, ByRef Image As BitmapImage, _
                        ByVal Text As String, ByVal Selected As Boolean)
        Items.Add(New ZuneCardr.Item(ID, Image, Text, Selected))
    End Sub

    ''' <summary>GetItems</summary>
    ''' <param name="ListBox">ListBox</param>
    ''' <remarks></remarks>
    Private Sub GetItems(ByRef ListBox As ListBox)
        ListBox.Items.Clear() ' Reset ListBox
        For Each Item As ZuneCardr.Item In Items
            ListBox.Items.Add(Item) ' Add Item
        Next
    End Sub

    ''' <summary>GetLinks</summary>
    ''' <remarks>Gets the Text and URLs for Profile</remarks>
    Private Sub GetLinks()
        For Each Destination As ZuneCardr.Destination In Social.Destinations
            Select Case Destination.Type
                Case ZuneCardr.Destination.HOME
                    ProfileHome.NavigateUri = New Uri(Destination.URL) ' Home
                Case ZuneCardr.Destination.SEND_CARD
                    ProfileSend.NavigateUri = New Uri(Destination.URL) ' Send Card
                Case ZuneCardr.Destination.SEND_MSG
                    ProfileMessage.NavigateUri = New Uri(Destination.URL) ' Send Message
            End Select
        Next
    End Sub

    ''' <summary>PlaylistSource</summary>
    ''' <param name="Type">Playlist Type</param>
    ''' <remarks>Gets Covers and Text from Playlists</remarks>
    Private Sub PlaylistSource(ByVal Type As String)
        Dim Index As Integer = ZuneCardr.Card.MIN_COVER
        For Each Playlist As ZuneCardr.Playlist In Social.Playlists
            If Playlist.Type = Type Then ' Compare Type
                If Type = ZuneCardr.Playlist.PLAYED Then ' Artist
                    For Each Artist As ZuneCardr.Artist In Playlist.Artists
                        If Artist.Selected And Index <= ZuneCardr.Card.MAX_COVER Then
                            Card.CoverImage(Index) = Artist.ImageLarge
                            Card.CoverText(Index) = Artist.Name
                            Index += 1
                        End If
                    Next
                Else ' Favourites or Recent
                    For Each Track As ZuneCardr.Track In Playlist.Tracks
                        If Track.Selected And Index <= ZuneCardr.Card.MAX_COVER Then
                            Card.CoverImage(Index) = Track.Album.ImageLarge
                            Card.CoverText(Index) = Track.Name
                            Index += 1
                        End If
                    Next
                End If
            End If
        Next
    End Sub

    ''' <summary>BadgeSource</summary>
    ''' <remarks>Gets Images and Text from Badges</remarks>
    Private Sub BadgeSource()
        Dim Index As Integer = ZuneCardr.Card.MIN_COVER
        For Each Badge As ZuneCardr.Badge In Social.Badges
            If Badge.Selected And Index <= ZuneCardr.Card.MAX_COVER Then
                Card.CoverImage(Index) = Badge.ImageLarge
                Card.CoverText(Index) = Badge.Name
                Index += 1
            End If
        Next
    End Sub

    ''' <summary>AllSource</summary>
    ''' <remarks>Gets Covers and Text from All List</remarks>
    Private Sub AllSource()
        Dim Index As Integer = ZuneCardr.Card.MIN_COVER
        For Each Item As ZuneCardr.Item In Items
            If Item.Selected And Index <= ZuneCardr.Card.MAX_COVER Then
                Card.CoverImage(Index) = Item.ImageLarge
                Card.CoverText(Index) = Item.Name
                Index += 1
            End If
        Next
    End Sub

    ''' <summary>Source</summary>
    ''' <remarks>Source for Card Data (Favourites, Recent, Badges or All)</remarks>
    Private Sub Source(ByVal Type As ZuneCardr.Card.CardSource)
        Dim Index As Integer
        For Index = ZuneCardr.Card.MIN_COVER To ZuneCardr.Card.MAX_COVER ' Reset Covers
            Card.CoverImage(Index) = Nothing ' Nothing
            Card.CoverText(Index) = "" ' Blank
        Next
        Select Case Type
            Case ZuneCardr.Card.CardSource.Favourites
                PlaylistSource(ZuneCardr.Playlist.FAVS)
            Case ZuneCardr.Card.CardSource.Recent
                PlaylistSource(ZuneCardr.Playlist.RECENT)
            Case ZuneCardr.Card.CardSource.Artists
                PlaylistSource(ZuneCardr.Playlist.PLAYED)
            Case ZuneCardr.Card.CardSource.Badges
                BadgeSource()
            Case ZuneCardr.Card.CardSource.All
                AllSource()
        End Select
    End Sub

    ''' <summary>Preview</summary>
    ''' <param name="Canvas">Canvas to Preview</param>
    ''' <remarks>Helper Function</remarks>
    Private Sub Preview(ByVal Canvas As Canvas)
        CardPreview.Children.Clear() ' Reset Preview Pane
        CardPreview.Children.Add(Canvas) ' Add Canvas
        Card.Layout(Canvas)
    End Sub

    ''' <summary>UpdateDevice</summary>
    ''' <remarks>Updates Zune Device Resource</remarks>
    Public Sub UpdateDevice()
        Select Case CStr(Card.Zune) ' Set Device
            Case ZUNE_4, ZUNE_8, ZUNE_16 ' Scorpius
                Resources.Item(RES_DEVICE) = Resources.Item(RES_DEVICE_SCORPIUS)
            Case ZUNE_30 ' Keel
                Resources.Item(RES_DEVICE) = Resources.Item(RES_DEVICE_KEEL)
            Case ZUNE_80, ZUNE_120 ' Draco
                Resources.Item(RES_DEVICE) = Resources.Item(RES_DEVICE_DRACO)
        End Select
    End Sub

    ''' <summary>UpdateDisplayMenu</summary>
    ''' <remarks>Updates Display menu with Current Settings</remarks>
    Private Sub UpdateDisplayMenu()
        ShowAvatar.IsChecked = Card.ShowAvatar
        ShowBackground.IsChecked = Card.ShowBackground
        ShowCovers.IsChecked = Card.ShowCovers
        ShowCoverText.IsChecked = Card.ShowCoverText
        ShowPlays.IsChecked = Card.ShowPlays
        ShowBadges.IsChecked = Card.ShowBadges
        ShowStatus.IsChecked = Card.ShowStatus
        ShowLastPlayed.IsChecked = Card.ShowLastPlayed
        ShowWeblink.IsChecked = Card.ShowWeblink
        ShowZune.IsChecked = Card.ShowZune
    End Sub

    ''' <summary>UpdateZuneMenu</summary>
    ''' <remarks>Updates Zune Menu with Current Settings</remarks>
    Private Sub UpdateZuneMenu()
        Dim MenuItem As MenuItem = CType(FindName(NAME_PREFIX & Card.Zune), MenuItem)
        Dim RadioButton As RadioButton = CType(MenuItem.Icon, RadioButton)
        RadioButton.IsChecked = True
    End Sub

    ''' <summary>UpdateThemeMenu</summary>
    ''' <remarks>Updates the Theme Menu with Current Settings</remarks>
    Private Sub UpdateThemeMenu()
        Dim MenuItem As MenuItem = CType(FindName(THEME_PREFIX & Card.CurrentTheme.CurrentStyle), MenuItem)
        Dim RadioButton As RadioButton = CType(MenuItem.Icon, RadioButton)
        RadioButton.IsChecked = True
    End Sub

    ''' <summary>UpdateCustomMenu</summary>
    ''' <remarks>Updates the Custom Menu with Current Settings</remarks>
    Private Sub UpdateCustomMenu()
        CGradientStart.Icon = ColourSquare(Card.CustomTheme.GradientStart)
        CGradientEnd.Icon = ColourSquare(Card.CustomTheme.GradientEnd)
        CForeground.Icon = ColourSquare(Card.CustomTheme.Foreground)
        CBackground.Icon = ColourSquare(Card.CustomTheme.Background)
        CBorder.Icon = ColourSquare(Card.CustomTheme.Border)
        CSectionForeground.Icon = ColourSquare(Card.CustomTheme.SectionForeground)
        CSectionBackground.Icon = ColourSquare(Card.CustomTheme.SectionBackground)
        CItemForeground.Icon = ColourSquare(Card.CustomTheme.ItemForeground)
    End Sub

    ''' <summary>UpdateOutputMenu</summary>
    ''' <remarks>Updates the Output Menu with Current Settings</remarks>
    Private Sub UpdateOutputMenu()
        Dim MenuItem As MenuItem = CType(FindName(SIZE_PREFIX & Card.OutputSize), MenuItem)
        Dim RadioButton As RadioButton = CType(MenuItem.Icon, RadioButton)
        RadioButton.IsChecked = True
    End Sub

    ''' <summary>StepStart</summary>
    ''' <param name="Canvas">Prior Wizard Step Canvas</param>
    ''' <remarks>Wizard Start</remarks>
    Private Sub StepStart(ByRef Canvas As Canvas)
        CurrentStep = 1 ' Set to Start Step
        Canvas.Visibility = Windows.Visibility.Hidden ' Prior Canvas Invisible
        Canvas.IsEnabled = False ' Prior Canvas Disabled
        cvsStepOne.IsEnabled = True ' Step One Canvas Enabled
        cvsStepOne.Visibility = Windows.Visibility.Visible ' Step One Canvas Visible
        btnBack.Visibility = Windows.Visibility.Hidden ' Hide Back Button
        btnNext.Content = LABEL_NEXT
        ResetIndicators() ' Reset Progress Indicators
        Progress.Visibility = Windows.Visibility.Hidden ' Progress Invisible
        Social = New ZuneCardr.Social ' Reset Data
        ProfileAvatar.Visibility = Windows.Visibility.Hidden ' Hide Avatar
        ProfileAvatar.Source = Nothing ' Reset Avatar
        ProfileTag.Visibility = Windows.Visibility.Hidden ' Hide Tag
    End Sub

    ''' <summary>StepOne</summary>
    ''' <param name="Canvas">Prior Wizard Step Canvas</param>
    ''' <remarks>Wizard Step One</remarks>
    Private Sub StepOne(ByRef Canvas As Canvas)
        Me.Cursor = Cursors.Wait ' Hourglass
        Progress.Visibility = Windows.Visibility.Visible ' Progress Visible
        Canvas.Visibility = Windows.Visibility.Hidden ' Prior Canvas Invisible
        Canvas.IsEnabled = False ' Prior Canvas Disabled
        cvsStepOne.IsEnabled = True ' Step One Canvas Enabled
        cvsStepOne.Visibility = Windows.Visibility.Visible ' Step One Canvas Visible
        btnBack.Visibility = Windows.Visibility.Hidden ' Hide Back Button
        btnNext.Content = LABEL_NEXT
        ResetIndicators() ' Reset Progress Indicators
        GetStatus(STATUS_PENDING, EVENT_DOWNLOAD, Downloading.Content, _
                  Downloading.Foreground) ' Pending Download
        Try
            If Social.Download(ZuneTag.Text) Then ' Download
                GetStatus(STATUS_PENDING, EVENT_PROCESS, Processing.Content, _
                Processing.Foreground) ' Pending Process
            Else
                Me.Cursor = Cursors.Arrow ' Reset Cursor
                GetStatus(STATUS_FAILED, EVENT_DOWNLOAD, Downloading.Content, _
                          Downloading.Foreground) ' Download Failed
            End If
        Catch ex As Exception
            Me.Cursor = Cursors.Arrow ' Reset Cursor
            Social.ErrorText = ex.Message ' Set Error text
            Social.ExceptionText = ex.ToString ' Set Exception Text
            GetStatus(STATUS_FAILED, EVENT_DOWNLOAD, Downloading.Content, _
                          Downloading.Foreground) ' Download Failed
        End Try
    End Sub

    ''' <summary>StepTwo</summary>
    ''' <param name="Canvas">Prior Wizard Step Canvas</param>
    ''' <remarks>Wizard Step Two</remarks>
    Private Sub StepTwo(ByRef Canvas As Canvas)
        CurrentStep = 2 ' Set to Step Two
        Canvas.Visibility = Windows.Visibility.Hidden ' Prior Canvas Invisible
        Canvas.IsEnabled = False ' Prior Canvas Disabled
        Canvas.SetTop(cvsStepTwo, Canvas.GetTop(cvsStepOne)) ' Position Step Canvas Top
        Canvas.SetLeft(cvsStepTwo, Canvas.GetLeft(cvsStepOne)) ' Position Step Canvas Left
        cvsStepTwo.IsEnabled = True ' Step Two Canvas Enabled
        cvsStepTwo.Visibility = Windows.Visibility.Visible ' Step Two Canvas Visible
        btnBack.Visibility = Windows.Visibility.Visible ' Show Back Button
        UpdateDisplayMenu() ' Update Display Menu
        UpdateZuneMenu() ' Update Zune Menu
        UpdateThemeMenu() ' Update Theme Menu
        UpdateCustomMenu() ' Update Custom Menu
        UpdateOutputMenu() ' Update Output Menu
        Source(Card.Source(CStr(cboSource.SelectedItem))) ' Get the Source
        Preview(Card.Card(CStr(cboStyle.SelectedItem))) ' Get the Current Card
        btnNext.Content = LABEL_NEXT ' Set Next Button Text
    End Sub

    ''' <summary>StepThree</summary>
    ''' <param name="Canvas">Prior Wizard Step Canvas</param>
    ''' <remarks>Wizard Step Three</remarks>
    Private Sub StepThree(ByRef Canvas As Canvas)
        CurrentStep = 3 ' Set to Step Two
        Canvas.Visibility = Windows.Visibility.Hidden ' Prior Canvas Invisible
        Canvas.IsEnabled = False ' Prior Canvas Disabled
        Canvas.SetTop(cvsStepThree, Canvas.GetTop(cvsStepOne)) ' Position Step Canvas Top
        Canvas.SetLeft(cvsStepThree, Canvas.GetLeft(cvsStepOne)) ' Position Step Canvas Left
        cvsStepThree.IsEnabled = True ' Step Three Canvas Enabled
        cvsStepThree.Visibility = Windows.Visibility.Visible ' Step Three Canvas Visible
        Source(Card.Source(CStr(cboSource.SelectedItem))) ' Get the Source
        btnBack.Visibility = Windows.Visibility.Visible ' Show Back Button
        btnNext.Content = LABEL_FINISH ' Set Next Button Text to Finish
    End Sub

    ''' <summary>StepFinish</summary>
    ''' <returns>Cancel Event Value</returns>
    ''' <remarks>Wizard Finish Step</remarks>
    Private Function StepFinish() As Boolean
        Dim result As MsgBoxResult
        result = MsgBox(MESSAGE_FINISH, CType(MsgBoxStyle.Question + _
                        MsgBoxStyle.YesNo, MsgBoxStyle), APP_NAME) ' Show Message
        If result = MsgBoxResult.Yes Then ' If Yes
            End ' End Program
            Return False ' Don't Cancel Event
        Else ' If No
            Return True ' Cancel Event (Don't Close Form)
        End If
    End Function

    ' Private Properties

    ''' <summary>Items</summary>
    ''' <returns>List of Items</returns>
    ''' <remarks>This is the All Items Store</remarks>
    Private ReadOnly Property Items() As List(Of ZuneCardr.Item)
        Get
            Return _Items
        End Get
    End Property

    ' Form Methods

    Private Sub btnAbout_Click(ByVal sender As System.Object, _
                               ByVal e As System.Windows.RoutedEventArgs) _
                               Handles btnAbout.Click
        Dim strAbout As String
        strAbout = APP_NAME & " " & APP_VERSION & vbCrLf & My.Application.Info.Copyright & vbCrLf & vbCrLf
        strAbout = strAbout & "Zune, Zune Card, Zune Logos, Badge Images, Zune.net and related service are the property or copyright of the Microsoft Corporation, All Rights Reserved." & vbCrLf
        strAbout = strAbout & "Album Art / Artist Images are the property of their respective owners and are used from the Zune Card service only, other usage restrictions may apply." & vbCrLf & vbCrLf
        strAbout = strAbout & "Powered by Visual Basic 2008 Express Edition, " & APP_NAME & vbCrLf & " Written by RoguePlanetoid" & vbCrLf & vbCrLf
        strAbout = strAbout & "Thanks to Nir, sixlettervariables and MojoFilter from StackOverflow.com" & vbCrLf & vbCrLf
        strAbout = strAbout & "Visit " & APP_WEBLINK_PARTIAL & " for the latest Versions and Updates of " & APP_NAME & vbCrLf & vbCrLf
        strAbout = strAbout & "Software Licence Agreement" & vbCrLf & vbCrLf
        strAbout = strAbout & APP_NAME & " (""The Software"") may not be reverse engineered, de-compiled, or disassembled in whole or in part." & vbCrLf
        strAbout = strAbout & "Uses Zune Card Service Data which is freely published and available without restriction." & vbCrLf
        strAbout = strAbout & "The Software is protected by the copyright and intellectual property laws of the United Kingdom." & vbCrLf
        strAbout = strAbout & "Usage of the software does not transfer or infer any rights, merely the right to use the software, ownership and title rights remain that of the software author." & vbCrLf
        strAbout = strAbout & "Comentsys are not liable for any consequential, special, incidental, or indirect damages of any kind when using the software, in any event any liablity will not exceed the greater of the value of the software which is £0.00 (Free)." & vbCrLf & vbCrLf
        strAbout = strAbout & "--Changelog--" & vbCrLf & vbCrLf
        strAbout = strAbout & "Version " & APP_VERSION & vbCrLf
        strAbout = strAbout & "- New Zune Social Data Component using .NET 3.5 features." & vbCrLf
        strAbout = strAbout & "- New Application Interface and Zune Card using WPF/XAML." & vbCrLf
        strAbout = strAbout & "- New Zune Card features and styles, including NXE and Custom." & vbCrLf
        strAbout = strAbout & "- New and Improved Menus feature new Settings." & vbCrLf
        strAbout = strAbout & "- Improved Theme support and new GamerCard Theme." & vbCrLf
        strAbout = strAbout & "- Improved Card Quality and Card Image Size options." & vbCrLf & vbCrLf
        strAbout = strAbout & "Version 2.0.0.0" & vbCrLf & "- Added support for Opening and Saving Settings." & vbCrLf
        strAbout = strAbout & "- Changed Menu ordering and names, ""Draw"" is now first and called ""Settings"", ""Background"" is now ""Images""" & vbCrLf
        strAbout = strAbout & "- Added Zune display options to the Show menu with graphic and text indicator." & vbCrLf
        strAbout = strAbout & "- Added Style-based Themes support plus Open and Save ZuneCardr Settings such as Theme, Card Style and other Options," & vbCrLf & vbCrLf
        strAbout = strAbout & "Version 1.2.0.0" & vbCrLf & "- Added support for Reputation badges." & vbCrLf
        strAbout = strAbout & "- Added total badges indicator for Large Card and Xbox 360 Gamer Card Styles." & vbCrLf & vbCrLf
        strAbout = strAbout & "Version 1.1.0.1" & vbCrLf & "- Complete Re-write of Zune Card Service Code for ZuneCard Component" & vbCrLf
        strAbout = strAbout & "- Re-write of Zune Card Render Component including improved Image Quality and More Options" & vbCrLf
        strAbout = strAbout & "- Added more Zune Card Styles including Banner and Signature Styles" & vbCrLf & vbCrLf
        strAbout = strAbout & "Version 1.0.0.0" & vbCrLf & "- Original Implementation of Software"
        MessageDialog.ShowDialog(LABEL_ABOUT & " " & APP_NAME & " " & APP_VERSION, strAbout)
    End Sub

    Private Sub btnBack_Click(ByVal sender As System.Object, _
                              ByVal e As System.Windows.RoutedEventArgs) _
                              Handles btnBack.Click
        Select Case CurrentStep ' What Step are We One
            Case 1
                ' Do Nothing
            Case 2
                StepStart(cvsStepTwo) ' Go Back from Step Two
            Case 3
                StepTwo(cvsStepThree) ' Go Back from Step Three
        End Select
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, _
                              ByVal e As System.Windows.RoutedEventArgs) _
                              Handles btnNext.Click
        Select Case CurrentStep ' What Step are We One
            Case 1
                If Me.ZuneTag.Text <> "" Then ' Check for Blanks
                    StepOne(New Canvas) ' Do Step One & Two
                Else
                    MsgBox(MESSAGE_TAG, MsgBoxStyle.Exclamation, APP_NAME)
                End If
            Case 2
                StepThree(cvsStepTwo) ' Do Step Three
            Case 3
                StepFinish() ' Do Final Step
        End Select
    End Sub

    Private Sub btnDetails_Click(ByVal sender As System.Object, _
                                 ByVal e As System.Windows.RoutedEventArgs) _
                                 Handles btnDetails.Click
        MessageDialog.ShowDialog(LABEL_DETAILS, ErrorLog) ' Show Details
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, _
                            ByVal e As System.Windows.RoutedEventArgs) _
                            Handles btnCancel.Click
        Me.Close()
    End Sub

    Private Sub cboStyle_SelectionChanged(ByVal sender As System.Object, _
                                      ByVal e As System.Windows.Controls.SelectionChangedEventArgs) _
                                      Handles cboStyle.SelectionChanged
        Preview(Card.Card(CStr(cboStyle.SelectedItem))) ' Selected Card
    End Sub

    Private Sub cboSource_SelectionChanged(ByVal sender As System.Object, _
                                       ByVal e As System.Windows.Controls.SelectionChangedEventArgs) _
                                       Handles cboSource.SelectionChanged
        Source(Card.Source(CStr(cboSource.SelectedItem))) ' Selected Source
    End Sub

    ''' <summary>OpenSettings_Click</summary>
    ''' <param name="sender">Menu Item</param>
    ''' <param name="e">Event Arguments</param>
    ''' <remarks>Handles Open Settings Click Event</remarks>
    Private Sub OpenSettings_Click(ByVal sender As System.Object, _
                              ByVal e As System.Windows.RoutedEventArgs)
        Dim OpenDialog As New Microsoft.Win32.OpenFileDialog
        Dim CustomName As String = ""
        OpenDialog.Filter = FILTER_ZUNECARDR
        OpenDialog.CheckFileExists = True ' File Exists
        If OpenDialog.ShowDialog(Me) Then
            Try
                ' Load File
                Settings.Open(OpenDialog.FileName)
                ' Custom Style File
                If IO.File.Exists(Settings.Custom) And Settings.Custom <> "" Then
                    CustomName = Card.Custom(Settings.Custom) ' Open & Name
                    cboStyle.Items.Item(cboStyle.Items.Count - 1) = CustomName & " " & CARD_CUSTOM
                End If
                ' Style Setting
                cboStyle.SelectedItem = Card.Name(Settings.Style, CustomName & " ")
                ' Display
                Card.ShowAvatar = Settings.ShowAvatar
                Card.ShowBackground = Settings.ShowBackground
                Card.ShowCovers = Settings.ShowCovers
                Card.ShowCoverText = Settings.ShowCoverText
                Card.ShowPlays = Settings.ShowPlays
                Card.ShowBadges = Settings.ShowBadges
                Card.ShowStatus = Settings.ShowStatus
                Card.ShowLastPlayed = Settings.ShowLastPlayed
                Card.ShowWeblink = Settings.ShowWeblink
                Card.ShowZune = Settings.ShowZune
                UpdateDisplayMenu() ' Update Menu
                ' Zune
                Card.Zune = Settings.Zune
                Card.ZuneColour = Settings.ZuneColour
                UpdateZuneMenu() ' Update Menu
                ' Custom
                Card.CustomTheme.GradientStart = Settings.GradientStart
                Card.CustomTheme.GradientEnd = Settings.GradientEnd
                Card.CustomTheme.Foreground = Settings.Foreground
                Card.CustomTheme.Background = Settings.Background
                Card.CustomTheme.Border = Settings.Border
                Card.CustomTheme.SectionForeground = Settings.SectionForeground
                Card.CustomTheme.SectionBackground = Settings.SectionBackground
                Card.CustomTheme.ItemForeground = Settings.ItemForeground
                ' Theme
                Card.Theme(Settings.Theme)
                UpdateThemeMenu() ' Update Menu
                UpdateCustomMenu() ' Update Menu
            Catch ex As Exception
                MsgBox(MESSAGE_SETTINGS_OPEN & vbCrLf & ex.Message, _
                       MsgBoxStyle.Critical, APP_NAME)
            End Try
        End If
    End Sub

    ''' <summary>SaveSettings_Click</summary>
    ''' <param name="sender">Menu Item</param>
    ''' <param name="e">Event Arguments</param>
    ''' <remarks>Handles Save Settings Click Event</remarks>
    Private Sub SaveSettings_Click(ByVal sender As System.Object, _
                              ByVal e As System.Windows.RoutedEventArgs)
        Dim SaveDialog As New Microsoft.Win32.SaveFileDialog
        SaveDialog.Filter = FILTER_ZUNECARDR
        SaveDialog.FileName = Card.Tag ' Default Filename
        SaveDialog.CheckPathExists = True ' Path Exists
        If SaveDialog.ShowDialog(Me) Then
            Try
                ' Style Settings
                Settings.Style = Card.CurrentStyle
                Settings.Custom = Card.Filename
                ' Display
                Settings.ShowAvatar = Card.ShowAvatar
                Settings.ShowBackground = Card.ShowBackground
                Settings.ShowCovers = Card.ShowCovers
                Settings.ShowCoverText = Card.ShowCoverText
                Settings.ShowPlays = Card.ShowPlays
                Settings.ShowBadges = Card.ShowBadges
                Settings.ShowStatus = Card.ShowStatus
                Settings.ShowLastPlayed = Card.ShowLastPlayed
                Settings.ShowWeblink = Card.ShowWeblink
                Settings.ShowZune = Card.ShowZune
                ' Zune
                Settings.Zune = Card.Zune
                Settings.ZuneColour = Card.ZuneColour
                ' Theme
                Settings.Theme = Card.CurrentTheme.CurrentStyle
                Settings.GradientStart = Card.CustomTheme.GradientStart
                Settings.GradientEnd = Card.CustomTheme.GradientEnd
                Settings.Foreground = Card.CustomTheme.Foreground
                Settings.Background = Card.CustomTheme.Background
                Settings.Border = Card.CustomTheme.Border
                Settings.SectionForeground = Card.CustomTheme.SectionForeground
                Settings.SectionBackground = Card.CustomTheme.SectionBackground
                Settings.ItemForeground = Card.CustomTheme.ItemForeground
                ' Save File
                Settings.Save(SaveDialog.FileName)
            Catch ex As Exception
                MsgBox(MESSAGE_SETTINGS_SAVE & vbCrLf & ex.Message, _
                       MsgBoxStyle.Critical, APP_NAME)
            End Try
        End If
    End Sub

    ''' <summary>Style_Click</summary>
    ''' <param name="sender">Menu Item</param>
    ''' <param name="e">Event Arguments</param>
    ''' <remarks>Handles Custom Style Click Event</remarks>
    Private Sub Style_Click(ByVal sender As System.Object, _
                              ByVal e As System.Windows.RoutedEventArgs)
        Dim Name As String = ""
        Dim OpenDialog As New Microsoft.Win32.OpenFileDialog
        OpenDialog.Filter = FILTER_CUSTOM
        OpenDialog.CheckFileExists = True ' File Exists
        If OpenDialog.ShowDialog(Me) Then
            Try
                Name = Card.Custom(OpenDialog.FileName) ' Name
                cboStyle.Items.Item(cboStyle.Items.Count - 1) = Name & " " & CARD_CUSTOM
            Catch ex As Exception
                MsgBox(MESSAGE_CUSTOM & vbCrLf & ex.Message, _
                       MsgBoxStyle.Critical, APP_NAME)
            End Try
        End If
    End Sub

    ''' <summary>Display_Click</summary>
    ''' <param name="sender">Menu Item</param>
    ''' <param name="e">Event Arguments</param>
    ''' <remarks>Handles Display Menu Checked and UnChecked Events</remarks>
    Private Sub Display_Click(ByVal sender As System.Object, _
                              ByVal e As System.Windows.RoutedEventArgs)
        Dim MenuItem As MenuItem = CType(sender, MenuItem)
        Select Case CStr(MenuItem.Name)
            Case ZuneCardr.Card.SHOW_AVATAR
                Card.ShowAvatar = MenuItem.IsChecked
            Case ZuneCardr.Card.SHOW_BACKGROUND
                Card.ShowBackground = MenuItem.IsChecked
            Case ZuneCardr.Card.SHOW_COVERS
                Card.ShowCovers = MenuItem.IsChecked
            Case ZuneCardr.Card.SHOW_COVER_TEXT
                Card.ShowCoverText = MenuItem.IsChecked
            Case ZuneCardr.Card.SHOW_PLAYS
                Card.ShowPlays = MenuItem.IsChecked
            Case ZuneCardr.Card.SHOW_BADGES
                Card.ShowBadges = MenuItem.IsChecked
            Case ZuneCardr.Card.SHOW_STATUS
                Card.ShowStatus = MenuItem.IsChecked
            Case ZuneCardr.Card.SHOW_LAST_PLAYED
                Card.ShowLastPlayed = MenuItem.IsChecked
            Case ZuneCardr.Card.SHOW_WEBLINK
                Card.ShowWeblink = MenuItem.IsChecked
            Case ZuneCardr.Card.SHOW_ZUNE
                Card.ShowZune = MenuItem.IsChecked
        End Select
    End Sub

    ''' <summary>Zune_Click</summary>
    ''' <param name="sender">Menu Item</param>
    ''' <param name="e">Event Arguments</param>
    ''' <remarks>Handles Zune Menu Click Events</remarks>
    Private Sub Zune_Click(ByVal sender As System.Object, _
                          ByVal e As System.Windows.RoutedEventArgs)
        Dim MenuItem As MenuItem = CType(sender, MenuItem)
        Dim RadioButton As RadioButton = CType(MenuItem.Icon, RadioButton)
        RadioButton.IsChecked = True
        If RadioButton.IsChecked Then
            Card.Zune = MenuItem.Name.Replace(NAME_PREFIX, "") ' Remove Prefix
            UpdateDevice() ' Update Device
        End If
    End Sub

    ''' <summary>ZuneColour_Click</summary>
    ''' <param name="sender">Menu Item</param>
    ''' <param name="e">Event Arguments</param>
    ''' <remarks>Handles Zune Colour Click Event</remarks>
    Private Sub ZuneColour_Click(ByVal sender As System.Object, _
                             ByVal e As System.Windows.RoutedEventArgs)
        Card.ZuneColour = ShowColorDialog(Card.ZuneColour, ZUNE_COLOUR, ZuneCardr.Colours.Zune(Card.ZuneColour))
    End Sub

    ''' <summary>Theme_Click</summary>
    ''' <param name="sender">Menu Item</param>
    ''' <param name="e">Event Arguments</param>
    ''' <remarks>Handles Theme Menu Click Events</remarks>
    Private Sub Theme_Click(ByVal sender As System.Object, _
                          ByVal e As System.Windows.RoutedEventArgs)
        Dim MenuItem As MenuItem = CType(sender, MenuItem)
        Dim RadioButton As RadioButton = CType(MenuItem.Icon, RadioButton)
        RadioButton.IsChecked = True
        If RadioButton.IsChecked Then
            Card.Theme(CType(MenuItem.Name.Replace(THEME_PREFIX, ""),  _
                                   ZuneCardr.Theme.Style))
        End If
    End Sub

    ''' <summary>Custom_Click</summary>
    ''' <param name="sender">Menu Item</param>
    ''' <param name="e">Event Arguments</param>
    ''' <remarks>Handles Custom Menu Click Events</remarks>
    Private Sub Custom_Click(ByVal sender As System.Object, _
                             ByVal e As System.Windows.RoutedEventArgs)
        Dim MenuItem As MenuItem = CType(sender, MenuItem)
        Dim Name As String = MenuItem.Name.Replace(CUSTOM_PREFIX, "") ' Remove Prefix
        Select Case Name
            Case ZuneCardr.Card.RES_GRADIENT_START
                Card.CustomTheme.GradientStart = ShowColorDialog(Card.CustomTheme.GradientStart, Name, ZuneCardr.Colours.GradientStart(Card.CustomTheme.GradientStart))
            Case ZuneCardr.Card.RES_GRADIENT_END
                Card.CustomTheme.GradientEnd = ShowColorDialog(Card.CustomTheme.GradientEnd, Name, ZuneCardr.Colours.GradientEnd(Card.CustomTheme.GradientEnd))
            Case ZuneCardr.Card.RES_FOREGROUND
                Card.CustomTheme.Foreground = ShowColorDialog(Card.CustomTheme.Foreground, Name, ZuneCardr.Colours.Foreground(Card.CustomTheme.Foreground))
            Case ZuneCardr.Card.RES_BACKGROUND
                Card.CustomTheme.Background = ShowColorDialog(Card.CustomTheme.Background, Name, ZuneCardr.Colours.Background(Card.CustomTheme.Background))
            Case ZuneCardr.Card.RES_BORDER
                Card.CustomTheme.Border = ShowColorDialog(Card.CustomTheme.Border, Name, ZuneCardr.Colours.Border(Card.CustomTheme.Border))
            Case ZuneCardr.Card.RES_SECTION_FOREGROUND
                Card.CustomTheme.SectionForeground = ShowColorDialog(Card.CustomTheme.SectionForeground, Name, ZuneCardr.Colours.SectionForeground(Card.CustomTheme.SectionForeground))
            Case ZuneCardr.Card.RES_SECTION_BACKGROUND
                Card.CustomTheme.SectionBackground = ShowColorDialog(Card.CustomTheme.SectionBackground, Name, ZuneCardr.Colours.SectionBackground(Card.CustomTheme.SectionBackground))
            Case ZuneCardr.Card.RES_ITEM_FOREGROUND
                Card.CustomTheme.ItemForeground = ShowColorDialog(Card.CustomTheme.ItemForeground, Name, ZuneCardr.Colours.ItemForeground(Card.CustomTheme.ItemForeground))
        End Select
        Card.Theme(Card.CurrentTheme.CurrentStyle) ' Refresh Theme
        UpdateCustomMenu() ' Update Custom Menu
    End Sub

    ''' <summary>Save_Click</summary>
    ''' <param name="sender">Sender</param>
    ''' <param name="e">Event Arguments</param>
    ''' <remarks>Handles Save Image Event</remarks>
    Private Sub Save_Click(ByVal sender As System.Object, _
                       ByVal e As System.Windows.RoutedEventArgs)
        Dim SaveDialog As New Microsoft.Win32.SaveFileDialog
        SaveDialog.Filter = FILTER_SAVE ' Use Save Format
        SaveDialog.CheckPathExists = True ' Check Path Exists
        SaveDialog.FileName = Card.Tag ' Use Tag for Default Filename
        If SaveDialog.ShowDialog(Me) Then
            Try
                Card.Save(SaveDialog.FileName)
            Catch ex As Exception
                MsgBox(MESSAGE_SAVE & vbCrLf & ex.Message, _
                       MsgBoxStyle.Critical, APP_NAME)
            End Try
        End If
    End Sub

    ''' <summary>Copy_Click</summary>
    ''' <param name="sender">Sender</param>
    ''' <param name="e">Event Arguments</param>
    ''' <remarks>Handles Copy Image Event</remarks>
    Private Sub Copy_Click(ByVal sender As System.Object, _
                       ByVal e As System.Windows.RoutedEventArgs)
        Card.Copy()
    End Sub

    ''' <summary>CopyWeblink_Click</summary>
    ''' <param name="sender">Sender</param>
    ''' <param name="e">Event Arguments</param>
    ''' <remarks>Handles Copy Weblink Event</remarks>
    Private Sub CopyWeblink_Click(ByVal sender As System.Object, _
                       ByVal e As System.Windows.RoutedEventArgs)
        Clipboard.SetText(Social.Weblink)
    End Sub

    ''' <summary>Output_Click</summary>
    ''' <param name="sender">Menu Item</param>
    ''' <param name="e">Event Arguments</param>
    ''' <remarks>Handles Output Size Click Events</remarks>
    Private Sub Output_Click(ByVal sender As System.Object, _
                          ByVal e As System.Windows.RoutedEventArgs)
        Dim MenuItem As MenuItem = CType(sender, MenuItem)
        Dim RadioButton As RadioButton = CType(MenuItem.Icon, RadioButton)
        RadioButton.IsChecked = True
        If RadioButton.IsChecked Then
            Card.OutputSize = CInt(MenuItem.Name.Replace(SIZE_PREFIX, "")) ' Remove Prefix
        End If
    End Sub

    ' Window Methods

    Private Sub Main_Loaded(ByVal sender As Object, _
                            ByVal e As System.Windows.RoutedEventArgs) _
                            Handles Me.Loaded
        Me.Title = APP_NAME ' 1200, 764
        Me.Height = 440
        Me.Width = 600
        Me.MaxHeight = Me.Height
        Me.MaxWidth = Me.Width
        cvsStepTwo.Visibility = Windows.Visibility.Hidden
        cvsStepThree.Visibility = Windows.Visibility.Hidden
        Card.StyleList(cboStyle) ' Get Styles
        Card.SourceList(cboSource) ' Get Sources
        StepStart(New Canvas) ' Set up Start Step
    End Sub

    Private Sub Main_Closing(ByVal sender As Object, _
                             ByVal e As System.ComponentModel.CancelEventArgs) _
                             Handles Me.Closing
        e.Cancel = StepFinish() ' Confirm Close
    End Sub

    Private Sub Main_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Closed
        End ' Exit Application
    End Sub

End Class
